//Component Object
const app = getApp();
const { apiInstance } = app

Component({
  properties: {
    data: {
      type: Object,
      value: {},
      observer: function (e) {
        if (e) {

          this.setData({
            form: e.shenBao,
            approvalStatusCurrent: e.shenBao?.approvalStatus || [],
            reviewDataCurrent: e.shenBao?.reviewData || [],
          })
        }
      }
    },
    isEdit: {
      type: Boolean,
      value: false,
      observer: function (e) {
        if (e) {
          this.setData({
            isEdit: e,
          })
        }
      }
    },
  },
  data: {
    form: {
      effluent: '',
      effluentTableData: [{
        word1: '',
        word2: '',
        word3: '',
        word4: ''
      }],
      exhaustGas: '',
      exhaustGasTableData: [{
        word1: '',
        word2: '',
        word3: '',
        word4: ''
      }],
      noise: '',
      noiseTableData: [{
        word1: '',
        word2: '',
        word3: '',
        word4: ''
      }],
      solidWaste: '',
      solidWasteTableData: [{
        word1: '',
        word2: '',
        word3: '',
        word4: ''
      }],
      emergencyFacilities: '',
      emergencyFacilitiesTableData: [{
        word1: '',
        word2: '',
        word3: '',
        word4: ''
      }],
      changeEffluent: '',
      changeEffluentDesc: '',
      ecologicalProtection: '',
      checkDepart: []
    },
    isEdit: false,
    approvalStatusCurrent: [],
    reviewDataCurrent: [],
    effluentCurrent: '',
    exhaustGasCurrent: '',
    noiseCurrent: '',
    solidWasteCurrent: '',
    emergencyFacilitiesCurrent: '',
    changeEffluentCurrent: '',
    ecologicalProtectionCurrent: '',
    approvalStatusList: [{
      id: 1,
      name: '在公司环评审批范围内，无需做环评'
    }, {
      id: 2,
      name: '在公司环评审批范围内，要重新环评'
    }, {
      id: 3,
      name: '在公司环评审批范围外，要报批环评'
    }],
    reviewDataList: [{
      id: 1,
      name: '设计方案'
    },
    {
      id: 2,
      name: '设计图纸'
    },
    {
      id: 3,
      name: '平面布置图'
    },
    {
      id: 4,
      name: '施工详图'
    },
    {
      id: 5,
      name: '设备设施说明'
    },
    {
      id: 6,
      name: '设备设施明细清单'
    },
    {
      id: 7,
      name: '污染防治方案'
    },
    {
      id: 8,
      name: '其他'
    },

    ],
    isOrNotList: [{
      id: 1,
      name: '是'
    }, {
      id: 2,
      name: '否'
    }],
    effluentHeaders: [{
      label: '废水主要来源',
      value: 'word1'
    },
    {
      label: '成份',
      value: 'word2'
    },
    {
      label: '水量',
      value: 'word3'
    },
    {
      label: '治理措施',
      value: 'word4'
    },
    ],
    effluentData: [{
      word1: '',
      word2: '',
      word3: '',
      word4: ''
    }],

    exhaustGasHeaders: [{
      label: '废气主要来源',
      value: 'word1'
    },
    {
      label: '成份',
      value: 'word2'
    },
    {
      label: '是否属于恶臭气体',
      value: 'word3'
    },
    {
      label: '治理措施',
      value: 'word4'
    },
    ],
    exhaustGasData: [{
      word1: '',
      word2: '',
      word3: '',
      word4: ''
    }],


    noiseHeaders: [{
      label: '噪音来源',
      value: 'word1'
    },
    {
      label: '噪音值',
      value: 'word2'
    },
    {
      label: '作业时间',
      value: 'word3'
    },
    {
      label: '治理措施',
      value: 'word4'
    },
    ],
    noiseData: [{
      word1: '',
      word2: '',
      word3: '',
      word4: ''
    }],

    solidWasteHeaders: [{
      label: '类型',
      value: 'word1'
    },
    {
      label: '主要成份',
      value: 'word2'
    },
    {
      label: '数量',
      value: 'word3'
    },
    {
      label: '处置方式',
      value: 'word4'
    },
    ],
    solidWasteData: [{
      word1: '',
      word2: '',
      word3: '',
      word4: ''
    }],

    emergencyFacilitiesHeaders: [{
      label: '应急设施名称',
      value: 'word1'
    },
    {
      label: '数量或规格',
      value: 'word2'
    },
    {
      label: '用途',
      value: 'word3'
    },
    {
      label: '管理责任人',
      value: 'word4'
    },
    ],
    emergencyFacilitiesData: [{
      word1: '',
      word2: '',
      word3: '',
      word4: ''
    }]
  },
  methods: {
    handleApprovalStatusChange({ detail }) {
      this.data.approvalStatusCurrent ??= [];
      const index = this.data.approvalStatusCurrent?.indexOf(detail.value);
      (index == -1 || index == 'undefined') ? this.data.approvalStatusCurrent.push(detail.value) : this.data.approvalStatusCurrent.splice(index, 1);
      this.setData({
        approvalStatusCurrent: this.data.approvalStatusCurrent,
        'form.approvalStatus': this.data.approvalStatusCurrent
      });
    },
    handleReviewDataCurrentChange({ detail }) {
      this.data.reviewDataCurrent ??= [];
      const index = this.data.reviewDataCurrent?.indexOf(detail.value);
      (index == -1 || index == 'undefined') ? this.data.reviewDataCurrent.push(detail.value) : this.data.reviewDataCurrent.splice(index, 1);
      this.setData({
        reviewDataCurrent: this.data.reviewDataCurrent,
        'form.reviewData': this.data.reviewDataCurrent
      });
    },

    handleEffluentChange({ detail }) {
      this.setData({
        effluentCurrent: detail.value,
        'form.effluent': detail.value,
      });
    },

    handleExhaustGasChange({ detail }) {
      this.setData({
        exhaustGasCurrent: detail.value,
        'form.exhaustGas': detail.value,
      });
    },
    handleNoiseChange({ detail }) {
      this.setData({
        noiseCurrent: detail.value,
        'form.noise': detail.value,
      });
    },
    handleSolidWasteChange({ detail }) {
      this.setData({
        solidWasteCurrent: detail.value,
        'form.solidWaste': detail.value,
      });
    },
    handleEmergencyFacilitiesChange({ detail }) {
      this.setData({
        emergencyFacilitiesCurrent: detail.value,
        'form.emergencyFacilities': detail.value,
      });
    },
    handleChangeEffluentChange({ detail }) {
      this.setData({
        changeEffluentCurrent: detail.value,
        'form.changeEffluent': detail.value
      });
    },

    handleEcologicalProtectionChange({ detail }) {
      this.setData({
        ecologicalProtectionCurrent: detail.value,
        'form.ecologicalProtection': detail.value
      });
    },

    bindValue(e){

      this.setData({
        [e.target.dataset.itemname]:e.detail.detail.value,
      });
    },


    getForm(){
      return Object.assign({},this.data.form, 
        (this.data.form?.effluent=='是'?{effluentTableData:this.selectComponent("#effluentTable")?.data.data}:{}),
        (this.data.form?.exhaustGas=='是'?{exhaustGasTableData:this.selectComponent("#exhaustGasTable")?.data.data}:{}),
        (this.data.form?.noise=='是'?{noiseTableData:this.selectComponent("#noiseTable")?.data.data}:{}),
        (this.data.form?.solidWaste=='是'?{solidWasteTableData:this.selectComponent("#solidWasteTable")?.data.data}:{}),
        (this.data.form?.emergencyFacilities=='是'?{emergencyFacilitiesTableData:this.selectComponent("#emergencyFacilitiesTable")?.data.data}:{})

      )

    },

  },
  lifetimes: {
    created: async function () {

    },
    attached: function () {

    },
    ready: async function () {


    },
    moved: function () {

    },
    detached: function () {

    }
  }

});